package com.ipt.frm.pw;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.PropertyConfigurator;

import com.ipartek.formacion.DAO.MySqlAlumnoDAO;
import com.ipartek.formacion.DAO.MySqlDAOFactory;
import com.ipartek.formacion.bean.Alumno;


/**
 * Servlet implementation class servletRanking
 */
public class servletRanking extends ServletMaestro {	
	private static final long serialVersionUID = -5186174395080599897L;
	
	private static final String LOG4J_PROPERTIES = "config/log4j.properties";
	private static MySqlDAOFactory factoriaDAO = null;
	private static MySqlAlumnoDAO mySqlAlumno = null;
	private static ArrayList<Alumno> listaAlumnos = new ArrayList<Alumno>();
	/**
     * @see HttpServlet#HttpServlet()
     */
    public servletRanking() {
        super();       
    }
    
    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    	
    	try {
    		PropertyConfigurator.configure(LOG4J_PROPERTIES);
    		
	    	//llamar a base de datos, y generar arraylist    		    	
	    	factoriaDAO = new MySqlDAOFactory();
	    	mySqlAlumno = factoriaDAO.getInterfaceAlumnoDAO();			
			listaAlumnos = mySqlAlumno.getRankingGlobal();    	
    	
			request.setAttribute("title", "Ranking alumnos");
			//llamar a ranking.jsp para mostrarlo
			request.setAttribute("tblAlumnos", listaAlumnos);
    		RequestDispatcher dispacher = this.getServletContext().getRequestDispatcher("/ranking.jsp");
    		dispacher.forward(request, response);
    	} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

}
